package com.ushahidi.android.app.data;

import com.ushahidi.android.app.ImageManager;
import com.ushahidi.android.app.ListIncidentText;
import com.ushahidi.android.app.R;
import com.ushahidi.android.app.util.Util;

import android.database.Cursor;
import android.text.TextUtils;

/*************************************************
 * Modified by OceanMaster
 * To remain compatible with IncidentsData
 * Because lots of library require incidentData
 *************************************************/

/***********************************************************
 * You can still add resource-specific fields and function
 ***********************************************************/

public class ResourceData extends IncidentsData
{
    public ResourceData()
    {

    }

    public int getResourceId()
    {
	return this.incidentId;
    }

    public void setResourceId(int id)
    {
	this.incidentId = id;
    }

    public String getResourceTitle()
    {
	return this.incidentTitle;
    }

    public void setResourceTitle(String title)
    {
	this.incidentTitle = title;
    }

    public String getResourceDesc()
    {
	return this.incidentDesc;
    }

    public void setResourceDesc(String description)
    {
	this.incidentDesc = description;
    }

    public String getResourceThumbnail()
    {
	return this.incidentThumbnail;
    }

    public void setResourceThumbnail(String thumbnail)
    {
	this.incidentThumbnail = thumbnail;
    }

    public String getResourceImage()
    {
	return this.incidentImage;
    }

    public void setResourceImage(String image)
    {
	this.incidentImage = image;
    }

    public String getResourceCategories()
    {
	return this.incidentCategories;
    }

    public void setResourceCategories(String categories)
    {
	this.incidentCategories = categories;
    }

    public String getResourceLocation()
    {
	return this.incidentLocation;
    }

    public void setResourceLocation(String location)
    {
	this.incidentLocation = location;
    }

    public String getResourceLocLatitude()
    {
	return this.incidentLocLatitude;
    }

    public void setResourceLocLatitude(String latitude)
    {
	this.incidentLocLatitude = latitude;
    }

    public String getResourceLocLongitude()
    {
	return this.incidentLocLongitude;
    }

    public void setResourceLocLongitude(String longitude)
    {
	this.incidentLocLongitude = longitude;
    }

    public int getResourceVerified()
    {
	return this.incidentVerified;
    }

    public void setResourceVerified(int id)
    {
	this.incidentVerified = id;
    }

    public int getResourceMode()
    {
	return this.incidentMode;
    }

    public void setResourceMode(int id)
    {
	this.incidentMode = id;
    }

    public String getResourceDate()
    {
	return this.incidentDate;
    }

    public void setResourceDate(String date)
    {
	this.incidentDate = date;
    }
    public void setDataFromCursor(Cursor cursor)
    {
        String title;
        String status;
        String date;
        String description;
        String location;
        String categories;
        String media;
        String image;
        String thumbnails[];
        if (cursor.moveToFirst()) {
            int idIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_ID);
            int titleIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_TITLE);
            int dateIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_DATE);
            int verifiedIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_VERIFIED);
            int locationIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_LOC_NAME);

            int descIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_DESC);

            int categoryIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_CATEGORIES);

            int mediaIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_MEDIA);

            int imageIndex = cursor.getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_IMAGE);

            int latitudeIndex = cursor
                    .getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_LOC_LATITUDE);

            int longitudeIndex = cursor
                    .getColumnIndexOrThrow(UshahidiDatabase.RESOURCE_LOC_LONGITUDE);


            do {
                int id = Util.toInt(cursor.getString(idIndex));
                setResourceId(id);
                setResourceLocLatitude(cursor.getString(latitudeIndex));
                setResourceLocLongitude(cursor.getString(longitudeIndex));

                title = cursor.getString(titleIndex);
                setResourceTitle(title);

                description = cursor.getString(descIndex);
                setResourceDesc(description);

                categories = cursor.getString(categoryIndex);
                setResourceCategories(categories);

                location = cursor.getString(locationIndex);
                setResourceLocation(location);

                date = Util.formatDate("yyyy-MM-dd HH:mm:ss", cursor.getString(dateIndex),
                        "MMMM dd, yyyy 'at' hh:mm:ss aaa");

                setResourceDate(date);
                media = cursor.getString(mediaIndex);
                setResourceThumbnail(media);

                image = cursor.getString(imageIndex);
                setResourceImage(image);

                setResourceVerified(Util.toInt(cursor.getString(verifiedIndex)));  
            } while (cursor.moveToNext());
            cursor.close();
        }
    }

}
